package com.blog.study.study8;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

/**
 * 〈有关Redis的事务处理〉<br>
 *
 * @author 未绪
 * @time 2017/12/12 20:10
 */
public class JedisTransClockDemo {
    public static final String HOST="192.168.88.129";
    public static final int PORT=6380;

    public static void main(String[] args) {

        int balance=100;        //余额为100
        int debt=0;             //债务为0

        Jedis jedis=new Jedis(HOST,PORT);

        jedis.set("balance",balance+"");
        jedis.set("debt",debt+"");


        Transaction transaction=jedis.multi();

        transaction.watch("balance");
        transaction.decr("balance");
        transaction.incr("debt");

        transaction.exec();
    }
}
